<?php /* CALENDAR $Id: view.php,v 1.20.10.1 2006/06/05 12:44:07 nybod Exp $ */
$event_id = intval( dPgetParam( $_GET, "event_id", 0 ) );

// check permissions for this record
$perms =& $AppUI->acl();
$canEdit = $perms->checkModuleItem( $m, "edit", $event_id );

// check if this record has dependencies to prevent deletion
$msg = '';
$obj = new CEvent();
$canDelete = $obj->canDelete( $msg, $event_id );

// load the record data
if (!$obj->load( $event_id )) {
	$AppUI->setMsg( 'Event' );
	$AppUI->setMsg( 'invalidID', UI_MSG_ERROR, true );
	$AppUI->redirect();
} else {
	$AppUI->savePlace();
}

// load the event types
$types = dPgetSysVal( 'EventType' );

// load the event recurs types
$recurs =  array (
	'Never',
	'Hourly',
	'Daily',
	'Weekly',
	'Bi-Weekly',
	'Every Month',
	'Quarterly',
	'Every 6 months',
	'Every Year'
);

$assigned = $obj->getAssigned();


if (($obj->event_owner != $AppUI->user_id) && !($perms->checkModule("admin", "view"))) {
 $canEdit = false;
}

$df = $AppUI->getPref('SHDATEFORMAT');
$tf = $AppUI->getPref('TIMEFORMAT');

$start_date = $obj->event_start_date ? new CDate( $obj->event_start_date ) : null;
$end_date = $obj->event_end_date ? new CDate( $obj->event_end_date ) : null;
$event_project = db_LoadResult('SELECT project_name FROM projects where project_id=' . $obj->event_project);

// setup the title block
$titleBlock = new CTitleBlock( 'View Event' );
if ($canEdit) {
	$titleBlock->addButton($AppUI->_('new event'), 'index.php?m=calendar&amp;a=addedit');
	$titleBlock->addCell();
}
$titleBlock->addButton( 'month view', 'index.php?m=calendar&date='.$start_date->format( FMT_TIMESTAMP_DATE ) );
$titleBlock->addCell();
$titleBlock->addButton( 'day view', 'index.php?m=calendar&a=day_view&date='.$start_date->format( FMT_TIMESTAMP_DATE ) );
$titleBlock->addCell();
$titleBlock->show();
?>
<script language="javascript">
<?php
// security improvement:
// some javascript functions may not appear on client side in case of user not having write permissions
// else users would be able to arbitrarily run 'bad' functions
if ($canDelete) {
?>
function delIt() {
	if (confirm( "<?=$AppUI->_('eventDelete', UI_OUTPUT_JS)?>" )) {
		document.frmDelete.submit();
	}
}
<?php } ?>
</script>

<form name="frmDelete" action="index.php?m=calendar" method="post">
	<input type="hidden" name="dosql" value="do_event_aed" />
	<input type="hidden" name="del" value="1" />
	<input type="hidden" name="event_id" value="<?=$event_id?>" />
</form>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr title="<?=$AppUI->_($types[$obj->event_type])?>"><td class="tabon">
	<?
		echo '<img class="ico" src="'.dPfindImage( 'event'.$obj->event_type.'.png', 'calendar' ).'">&nbsp;'.
			 $obj->event_title;
	?>
	</td><td width="100%">&nbsp;</td></tr>
</table>
<table border="0" cellpadding="7" cellspacing="0" width="100%" class="infopanel">
<tr>
	<td width="100%">
	<?
		if ($canEdit) {
			showButton( 'edit this event', 'index.php?m=calendar&a=addedit&event_id='.$event_id );
			echo '&nbsp;';
			if ($canDelete) {
				showButton( 'delete event', 'js:delIt()' );
			}
		}
	?>
	</td>
</tr>
</table>
<table border="0" cellpadding="7" cellspacing="0" width="100%" class="subinfopanel">
<tr>
	<td valign="top" width="50%">
		<table cellspacing="0" cellpadding="3" width="100%" class="list">
		<tr class="second">
			<td align="right" nowrap="nowrap"><b><?=$AppUI->_('Starts')?></b></td>
			<td><?=$start_date ? $start_date->format( "$df $tf" ) : '-'?></td>
			<td width="50%"><b><?=$AppUI->_('Description')?></b></td>
		</tr>
		<tr class="second">
			<td align="right" nowrap="nowrap"><b><?=$AppUI->_('Ends')?></b></td>
			<td><?=$end_date ? $end_date->format( "$df $tf" ) : '-'?></td>
			<td width="50%" rowspan="<?=$obj->event_project ? '4' : '3'?>" valign="top">
				<div style="width: 99%; height: 100px; overflow: auto" class="text">
				<?=str_replace( chr(10), '<br/>', $obj->event_description)?>&nbsp;
				</div>
			</td>
		</tr>
		<? if ($obj->event_project) { ?>
		<tr class="second">
			<td align="right" nowrap="nowrap"><b><?=$AppUI->_('Project')?></b></td>
			<td><a href='?m=projects&a=view&project_id=<?=$obj->event_project ?>'><?=$event_project?></a></td>
		</tr>
		<? } ?>
		<tr class="second">
			<td align="right" nowrap="nowrap"><b><?=$AppUI->_('Recurs')?></b></td>
			<td><?=$AppUI->_($recurs[$obj->event_recurs])." (".$obj->event_times_recuring."&nbsp;".$AppUI->_('times').")" ?></td>
		</tr>
		<tr class="second">
			<td align="right" nowrap="nowrap" valign="top"><b><?=$AppUI->_('Attendees')?></b></td>
			<td valign="top"><?php
				if (is_array($assigned)) {
					$start = false;
					foreach ($assigned as $user) {
						if ($start)
							echo "<br/>";
						else
							$start = true;
						echo $user;
					}
				}
			?>
		</tr>
		</table>
		<?php
				require_once $AppUI->getSystemClass("CustomFields");
				$custom_fields = New CustomFields( $m, $a, $obj->event_id, "view" );
				$custom_fields->printHTML();
		?>

	</td>
</tr>
</table>
